<%- include('header'); %>

<body class="hold-transition register-page">
<div class="register-box">
    <div class="register-logo">
    <a href="/"><b>Dapps</b>应用商店</a>
    </div>

    <div class="card">
    <div class="card-body register-card-body">
        <p class="login-box-msg">注册</p>

        <form>
        <div class="input-group mb-3">
            <input type="text" id="username" class="form-control" placeholder="用户名" value="">
            <div class="input-group-append">
            <div class="input-group-text">
                <span class="fas fa-user"></span>
            </div>
            </div>
        </div>
        <div class="input-group mb-3">
            <input type="email" id="email" class="form-control" placeholder="邮箱" value="">
            <div class="input-group-append">
            <div class="input-group-text">
                <span class="fas fa-envelope"></span>
            </div>
            </div>
        </div>
        <div class="input-group mb-3">
            <input type="password" id="pwd1" class="form-control" placeholder="密码" value="">
            <div class="input-group-append">
            <div class="input-group-text">
                <span class="fas fa-lock"></span>
            </div>
            </div>
        </div>
        <div class="input-group mb-3">
            <input type="password" id="pwd2" class="form-control" placeholder="确认密码" value="">
            <div class="input-group-append">
            <div class="input-group-text">
                <span class="fas fa-lock"></span>
            </div>
            </div>
        </div>
        <div class="row">
            <a href="#" id="register" class="btn btn-block btn-primary">
                    注册
            </a>
            
        </div>
        </form>
        <div class="social-auth-links text-center">
            <a href="/html/v1/login" class="text-center">我已经有账号</a>
        </div>
        
    </div>
    <!-- /.form-box -->
    </div><!-- /.card -->
</div>
<!-- /.register-box -->
<script>
    $(function(){
        $('#register').click(function() {
            var username = $('#username').val();
            var email = $('#email').val();
            var pwd1 = $('#pwd1').val();
            var pwd2 = $('#pwd2').val();
            var params = {
                out_url: "register",
                method: 'POST',
                data: {
                    username: username,
                    email: email,
                    pwd1: pwd1,
                    pwd2: pwd2
                }
            };
            $.post('/api/v1/home/outapi',params,function(result){         
                if (result.code !== 0) {
                    alert(result.message);
                } else {
                    localStorage.setItem('token', result.data.token);   
                    localStorage.setItem('uid', result.data.user_info.uid);
                    localStorage.setItem('user_info', JSON.stringify(result.data.user_info));
                    var url = "/html/v1/store/list";
                    window.location.href= url;
                }
            });    
	    });
    })
</script>

<!-- Bootstrap 4 -->
<script src="/public/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>